﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace HPPClientLibrary
{
    class OwnedFileBlocksXO : IXmlable
    {
        private string _fileHash;
        private string _blocksString;

        public string BlocksString
        {
            get { return _blocksString; }
        }

        public string FileHash
        {
            get { return _fileHash; }
        }

        public OwnedFileBlocksXO(string fileHash, string blocksString)
        {
            _fileHash = fileHash;
            _blocksString = blocksString;
        }

        public static XDocument Empty
        {
            get
            {
                XDocument xdoc = new XDocument();
                xdoc.Declaration = new XDeclaration("1.0", "utf-8", "yes");
                XElement file = new XElement("File");
                xdoc.Add(file);
                return xdoc;
            }
        }

        public XDocument ToXml()
        {
            XDocument xdoc = new XDocument();
            xdoc.Declaration = new XDeclaration("1.0", "utf-8", "yes");
            XElement file = new XElement("File");
            file.Add(new XElement("FileHash", new XAttribute("Hash", FileHash)));
            file.Add(new XElement("HasBlocks", new XAttribute("Blocks", BlocksString)));
            xdoc.Add(file);
            return xdoc;
        }

        public OwnedFileBlocksXO FromXml(string xml)
        {
            throw new NotImplementedException();
            /*
            try
            {
                XDocument doc = XDocument.Parse(xml);
            }
            catch (Exception e)
            {
                CommonLogger.Logger.Info(this.GetType().Name, e);
                throw;
            }*/
        }
    }
}
